/*
 * @Author: wurangkun
 * @Date: 2024-05-14 12:00:38
 * @LastEditTime: 2024-05-22 19:39:36
 * @LastEditors: wurangkun
 * @FilePath: \flutter_example\lib\home\home.dart
 * @Description: 
 */
import 'package:flutter/material.dart';
import 'package:flutter_example/common/UserModel.dart';
import 'package:flutter_example/common/global.dart';
import 'package:flutter_example/login/login.dart';
import 'package:flutter_example/models/index.dart';
import 'package:flutter_example/routes/routes.dart';
import 'package:flutter_example/widgets/JButton.dart';
import 'package:flutter_example/widgets/KButton.dart';
import 'package:provider/provider.dart';

class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  @override
  void initState() {
    // UserModel userModel = UserModel();

    super.initState();
    // if (!userModel.isLogin) {
    //   Navigator.pushNamed(context, 'login');
    // }
    print("initState");
  }

  @override
  void dispose() {
    super.dispose();
    print("dispose");
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Riverpod Demo'),
        centerTitle: true,
      ),
      body: Center(
          child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          KButton(
            child: const Text("动态添加列表数据"),
            onTap: () {
              Navigator.pushNamed(context, 'animatedList');
            },
          ),
          const SizedBox(height: 20),
          const AnimatedButton(
            text: "按钮",
          ),
          const SizedBox(height: 20),
          AnimatedButton(
            onTap: () {},
            text: "例子",
          ),
          const SizedBox(height: 20),
          AnimatedButton(
            onTap: () {
              Navigator.pushNamed(context, 'login');
            },
            text: "登录页面",
          ),
          const SizedBox(height: 20),
          AnimatedButton(
            onTap: () {
              // Provider.of<Global>(context).user = null;
              // Global.profile = null;
              // Provider.of<UserModel>(context, listen: false).logout();
              Global.profile.user = null;
              Navigator.pushNamedAndRemoveUntil(context, '/', (route) => false);
            },
            text: "退出登录",
          ),
        ],
      )),
    );
  }
}
